#include <glib.h>

static void my_log_handler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
{
    g_print("[domain:%s][LEVEL:%3d][%s]my_log_handler : %s \n",log_domain,log_level,user_data,message);
}

gint main(gint argc, gchar **argv)
{
    g_log_set_default_handler(my_log_handler, "User_Data");

    g_setenv ("G_MESSAGES_DEBUG", "all", TRUE);

    g_log ("foo", G_LOG_LEVEL_DEBUG, "foo debug");
    g_log ("foo", G_LOG_LEVEL_INFO, "foo info");
    g_log ("bar", G_LOG_LEVEL_MESSAGE, "bar message");
    g_log ("bar", G_LOG_LEVEL_WARNING, "bar warning");
    g_log ("baz", G_LOG_LEVEL_CRITICAL, "bar critical");

    g_print("set fatal mask: baz G_LOG_LEVEL_MESSAGE \n");
    g_log_set_fatal_mask("baz", G_LOG_LEVEL_MESSAGE);

    g_log ("foo", G_LOG_LEVEL_DEBUG, "foo debug");
    g_log ("foo", G_LOG_LEVEL_INFO, "foo info");
    g_log ("foo", G_LOG_LEVEL_MESSAGE, "foo message");
    g_log ("bar", G_LOG_LEVEL_MESSAGE, "bar message");
    g_log ("bar", G_LOG_LEVEL_WARNING, "bar warning");
    g_log ("baz", G_LOG_LEVEL_INFO, "baz info");
    g_log ("baz", G_LOG_LEVEL_CRITICAL, "baz critical");

    g_print("set always fatal: G_LOG_LEVEL_MESSAGE \n");
    g_log_set_always_fatal(G_LOG_LEVEL_MESSAGE);

    g_log ("foo", G_LOG_LEVEL_DEBUG, "foo debug");
    g_log ("foo", G_LOG_LEVEL_INFO, "foo info");
    g_log ("bar", G_LOG_LEVEL_MESSAGE, "bar message");
    g_log ("bar", G_LOG_LEVEL_WARNING, "bar warning");
    g_log ("baz", G_LOG_LEVEL_CRITICAL, "baz critical");

    return 0;
}
